<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<html>
<head>
<title>FINIAC | Finance Manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function formReset()
{
document.getElementById("frm1").reset();
}
</script>

<script language="JavaScript" src="../html/calendar_us.js"></script>
<script src="../script/jquery-1.7.1.min.js" type="text/javascript"></script>
	<link rel="stylesheet" href="../html/calendar.css">
<link href="../css/styles.css" rel="stylesheet" type="text/css">

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 5px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<script type="text/javascript">

function validate(form){
	var name = form.product.value;
	var qty = parseFloat(form.qtyAvail.value);
	var date=form.dateLastPurchase.value;

	var errors = [];
	 
	 if (!name) {
	  errors[errors.length] = "Enter product name or product code .";
	 }

	 if (!date) {
		  errors[errors.length] = "Select date of purchase .";
		 }
	 if (errors.length > 0) {

	  reportErrors(errors);
	  return false;
	 }
	  return true;
	}
	function reportErrors(errors){
	 var msg = "Please Enter Valide Data...\n";
	 for (var i = 0; i<errors.length; i++) {
	 var numError = i + 1;
	  msg += "\n" + numError + ". " + errors[i];
	}
	 alert(msg);
}

function setSelectValue (id, val) {
    document.getElementById(id).value = val;
}


function clearDate(){
	oFormObject = document.forms['updateStock'];
	oFormObject.elements["dateLastPurchase"].value = '';
	
}

$(function() {
$("#qtyPur").keydown(function(event) {
    $("#dateLastPurchase").val('');
});
});

</script>

</head>
	<c:forEach items="${productList}" var="product" varStatus="status">
<body onload="setSelectValue('purchaseUnit','${product.purchaseUnit}');">


<form:form action="updateStock.htm" commandName="product" name="updateStock" onsubmit="return validate(this);" >
<table width="100%" border="0">

		<tr>
			<td><span class="Bredcrumbs">Stock&gt;&gt; Add Stock&gt;&gt;</span></td>
		</tr>
		<tr>
			<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td width="9"><img src="../images/Tright_03_01.gif" width="9"
						height="29"></td>
					<td background="../images/Tcenter.gif" class="body"><strong
						class="boxheader"> Payment Entry </strong></td>

					<td width="10"><img src="../images/Tright_1_01.gif" width="9"
						height="29"></td>
				</tr>
				<tr>
					<td height="452" valign="top" background="../images/Tright_03_03.gif"></td>
				  <td valign="top" class="news">
					<table width="100%" cellspacing="1" cellpadding="2">
						<tr bgcolor="#FFFFFF">
							<td height="20" colspan="4">
							<div align="right">
							  <div id="div"><FONT color="red"></FONT> <FONT color="green"> </FONT>
                                  <div align="right" class="mandatoryfield">*Mandatory fields </div>
						      </div>
							</div>
							<div id="errorMessage"><FONT color="red"></FONT>
							<FONT color="green">  </FONT></div>
							</td>
						</tr>

						<tr>
							<td valign="top" class="news">
							<table width="100%" border="0" align="center" cellpadding="0"
								cellspacing="0">
								<tr>
									<td><img src="../images/01.gif" width="5" height="5" /></td>
									<td width="914" background="../images/02.gif"></td>
									<td><img src="../images/03.gif" width="5" height="5" /></td>
								</tr>
								<tr>
									<td width="5" background="../images/left.gif"></td>
									<td valign="top">
									<table width="100%" cellspacing="1" cellpadding="2">
					
				
						<tr>

							<td width="13%" height="25" class="row-odd">
							<input type="hidden" id="id" class="row-white"  name="id" value="${product.id }"/>
							<div align="right"><span class="Mandatory">*</span>Add item by name:</div>
							</td>
							<td width="33%" height="25" class="row-even"><span
								class="star">
							   <input type="text" id="product" class="row-white"  name="product" value="${product.product }"/>
							</span></td>
							<td width="15%" class="row-odd">
							<div align="right"><span class="Mandatory">*</span> Date:</div>
							</td>

							<td width="39%" class="row-even"><input type="text" id="dateLastPurchase" class="row-white"  name="dateLastPurchase" value="${product.dateLastPurchase }"/>
							<script language="JavaScript">
							new tcal ({
								// form name 
								'formname': 'updateStock',
								// input name 
								'controlname': 'dateLastPurchase'
							});</script></td>
						</tr>
						<tr>
							
						<td class="row-odd">
							<div align="right"><span class="Mandatory">*</span> Quantity Available :</div>
							</td>
							<td class="row-even"><span class="star">  <input type="text" id="qtyAvail" name="qtyAvail" class="row-white" value="${product.qtyAvail }"/></span></td>
							<td class="row-odd">
							<div align="right"> Quantity Purchased:</div>
							</td>
							<td class="row-even"><span class="star">  <input type="text" id="qtyPur" name="qtyPur" class="row-white" value="" /></span></td>
						</tr>

						<tr>
							<td height="25" class="row-odd">
							<div align="right"><span class="Mandatory">*</span>Purchased Price:</div></td>
							<td height="25" class="row-even"><input name="purchasePrice" name="purchasePrice" class="row-white" value="${product.purchasePrice }"/></td>
							<td class="row-odd">
							<div align="right"><span class="Mandatory">*</span> Per:</div>
							</td>
							<td class="row-even"><span class="star"><select name="purchaseUnit" id="purchaseUnit">
								<option value="N" label="Nos">Nos</option>
								<option value="L" label="Litre">Litre</option>
								<option value="M" label="Meter">Meter</option>
							</select></span></td>
						
							<td width="0%" height="25" class="row-odd">&nbsp;							</td>
						</tr>
					
						<tr>
							<td height="25" colspan="4">
						<!--  <form:errors path="dateLastPurchase" cssClass="error"/>
							<form:errors path="qtyAvail" cssClass="error"/>
						-->	
						
							</td>
						</tr>

							</table>
							    </td>
									<td width="5" height="29" background="../images/right.gif"></td>
								</tr>
			
								<tr>
									<td height="5"><img src="../images/04.gif" width="5" height="5" /></td>
									<td background="../images/05.gif"></td>
									<td><img src="../images/06.gif" /></td>
								</tr>
							</table>
							</td>
							<td valign="top" background="../images/Tright_3_3.gif" class="news"></td>
						</tr>


						<tr>
							<td height="25" colspan="4">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td width="45%" height="35">
									<div align="right">
										
										
											<input type="submit" name="submit" value="Submit"  class="formbutton">
										
									</div>
									</td>
									<td width="2%"></td>
									<td width="53%">
										
										
											<input type="reset" name="reset" value="Reset" onClick="formReset()" class="formbutton">
										
									</td>
								</tr>
								
							</table>
							
							</td>
						</tr>

					


					</table>
					</td>
					<td width="10" valign="top" background="../images/Tright_3_3.gif"
						class="news"></td>
				</tr>

				<tr>
					<td valign="top" background="../images/Tright_03_03.gif"></td>
					<td height="20" valign="top"></td>
					<td width="13" valign="top" background="../images/Tright_3_3.gif"
						class="news"></td>
				</tr>
				<tr>
					<td><img src="../images/Tright_03_05.gif" width="9" height="29" /></td>
					<td width="100%" background="../images/TcenterD.gif"></td>
					<td><img src="../images/Tright_02.gif" width="9" height="29" /></td>
				</tr>
			</table>
			</td>
		</tr>

	</table>
</form:form>
</body>
	</c:forEach>
</html>